import { loadEnv } from 'vite'

// 封装 代理服务和 端口号
export const createProxySever = (mode: string) => {
  const root = process.cwd()
  const { VITE_BASE_URL, VITE_PORT, VITE_PROXY_URL } = loadEnv(mode, root)
  return {
    port: Number(VITE_PORT),
    proxy: {
      [VITE_PROXY_URL]: {
        target: VITE_BASE_URL,
        changeOrigin: true,
        rewrite: (path: string) => path.replace(/^\/site/, ''),
      },
    },
  }
}
